﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Security.Domain;

namespace Security.View.QuickViews.Reports
{
    [DisplayName("Разрешение")]
    internal class PermissionQuickReport
    {
        public PermissionQuickReport(Permission permission)
        {
            Name = permission.Name;
            PermissionEmployees = permission.EmployeePermissions.Select(e => new AssociatedEmployeeReport(e)).ToArray();
            PermissionPosts = permission.PostPermissions.Select(p => new AssociatedPostReport(p)).ToArray();
        }

        [Browsable(false)]
        [DisplayName("Идентификатор")]
        public Guid ID { get; set; }
        [DisplayName("Название")]
        public string Name { get; set; }
        [DisplayName("Сотрудники")]
        public ICollection<AssociatedEmployeeReport> PermissionEmployees { get; set; }
        [DisplayName("Должности")]
        public ICollection<AssociatedPostReport> PermissionPosts { get; set; }
    }

    internal class AssociatedPostReport
    {
        public AssociatedPostReport(PostPermission postPermission)
        {
            Name  = postPermission.Post.Name;
            Expire = postPermission.Expire;
        }

        [DisplayName("Действительно до")]
        public DateTime? Expire { get; set; }
        [DisplayName("Название")]
        public string Name { get; set; }
    }

    internal class AssociatedEmployeeReport
    {
        public AssociatedEmployeeReport(EmployeePermission employeePermission)
        {
            Name = employeePermission.Employee.Lastname;
            Expire = employeePermission.Expire;
        }

        [DisplayName("Фамилия")]
        public string Name { get; set; }
        [DisplayName("Действительно до")]
        public DateTime? Expire { get; set; }
    }
}
